package edu.ccut.saturn.studio.logic.model.drop.logic;

import java.util.List;

import org.w3c.dom.Element;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.drop.LogicDropHandler;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnInformationNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnLogicNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnStartNode;
import edu.ccut.saturn.studio.logic.model.saturn.logic.SaturnLogicInLogic;

public class LogicLogicDropHandler extends LogicDropHandler {
	protected Shape getShape(Element root, String symbolicName) {
		try {
			SaturnLogicNode logicNode = new SaturnLogicInLogic();

			List<Shape> informations = informationNodeLoader.loadNodes(root);

			if (informations != null && informations.size() > 0) {
				SaturnInformationNode informationNode = (SaturnInformationNode) informations
						.get(0);

				String key = informationNode.getKey();
				String description = informationNode.getDescription();
				String name = informationNode.getName();

				logicNode.setDescription(description);
				logicNode.setKey(symbolicName.trim()+ LOGIC_DROP_HANDLER_TWO_DOT + key.trim());
				logicNode.setName(name);
			}

			List<Shape> starts = startNodeLoader.loadNodes(root);

			if (starts != null && starts.size() > 0) {
				SaturnStartNode startNode = (SaturnStartNode) starts.get(0);
				logicNode.setParameters(startNode.getParameters());
			}

			return logicNode;

		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}
}
